<?php

namespace App\Http\Controllers\Web;

use App\Http\Controllers\Controller;
use App\Models\Product;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cookie;

class CartController extends Controller
{

    public function apex(){
        $carts = Cookie::get('carts');
        $apex = [];
        if($carts){
            $carts = json_decode($carts,true);
            if($carts){
                $product_ids = array_keys($carts);
                $cart_product = Product::whereIn('id',$product_ids)->where('status',1)->get();
                $apex['product'] = $cart_product;
                $apex['num'] = $carts;
            }

        }
        $view = view('web.widgets.apex-cart',compact('apex'))->render();
        return $view;
    }
}
